class Solution {
public:
    int missingNumber(vector<int>& nums) {
        if(nums.size()==1&&nums[0]==0){return 1;}
        int maxn=*max_element(nums.begin(),nums.end());
        int totmaxn=0,totcur=0;
        for(int i=0;i<nums.size();i++){
            totcur+=nums[i];
            totmaxn+=i;
        }
        if(maxn==nums.size()){return totmaxn+maxn-totcur;}
        return totmaxn+maxn+1-totcur;
    }
};